package thread;


/**
 * @description: 接口实现方式来创建线程
 * @author: apple
 * @date:  2021/11/27 9:38 下午
 * @version 1.0
 **/
class Window2 implements Runnable {

    // 一共5张票
    private static int ticket = 100;

    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                System.out.println(Thread.currentThread().getName() + "，还剩：" + --ticket);
            } else {
                System.out.println(Thread.currentThread().getName() +"票已经卖完");
                break;
            }
        }

    }
}


public class WindowTest {

    public static void main(String[] args) {

        Window2 w = new Window2();
        Thread t1 = new Thread(w);
        Thread t2 = new Thread(w);
        Thread t3 = new Thread(w);

        t1.setName("窗口1");
        t2.setName("窗口2");
        t3.setName("窗口3");

        t1.start();
        t2.start();
        t3.start();
    }
}
